package com.chang.cheng.toutiaoserver.login.mapper;

import com.chang.cheng.toutiaoserver.model.user.pojos.Article;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Auther: asus
 * @Date: 2022/01/07 10:20
 * @Description:
 */
public interface ApArticleMapper {
    /**
     * 查询所有用户
     * 时间对比
     * @return
     */
    /*@Select("SELECT *  FROM ap_article WHERE channel_id = #{channel_id} " +
            "and DATE_FORMAT(created_time,'%Y-%m-%d %H:%i:%S')<=DATE_FORMAT(#{startDate} ,'%Y-%m-%d %H:%i:%S') " +
            "and DATE_FORMAT(created_time,'%Y-%m-%d %H:%i:%S')>DATE_FORMAT(#{endDate} ,'%Y-%m-%d %H:%i:%S')")*/
    @Select("SELECT *  FROM ap_article WHERE channel_id = #{channel_id} " +
            "and DATE_FORMAT(created_time,'%Y-%m-%d %H:%i:%S')<DATE_FORMAT(#{startDate} ,'%Y-%m-%d %H:%i:%S') " +
            "order by created_time desc limit 10 ")
    @Results(id = "userMap", value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "title", property = "title"),
            @Result(column = "author_id", property = "author_id"),
            @Result(column = "channel_id", property = "channel_id"),
            @Result(column = "images", property = "images"),
            @Result(column = "created_time", property = "pubdate"),
            @Result(column = "author_name", property = "aut_name")
    })
    List<Article> findArticles(@Param("channel_id") Long channel_id, @Param("startDate") String startDate);

    @Select("select count(id) from ap_article where channel_id = #{channel_id}")
    Long findCount(@Param("channel_id") Long channel_id);
}
